#!/bin/bash
#
# This script is just like the munki_deploySettings.sh script, only it caches
# the results on the filesystem instead of attempting to write the results
# immediately. munki_deploySettings.sh will check for the cache file in
# /tmp/ManagedInstalls.plist. If it finds that file, it will simply copy it to
# the target drive instead of asking the user for additional information.
#
plist="/private/var/tmp/${DS_PRIMARY_MAC_ADDRESS}"

SelectedManifest="${1}"

if [ "${SelectedManifest}" = "" ];then
  BASE_DIR=`dirname "${0}"`
  SelectedManifest=`"${BASE_DIR}/Munki Image Selector.app/Contents/MacOS/Munki Image Selector"`
  SelectedManifest="${SelectedManifest}/generic"
fi

echo "Caching munki group '${SelectedManifest}'"
defaults write "${plist}" ClientIdentifier -string "${SelectedManifest}"

if [ -e "${plist}.plist" ]; then
	echo "WROTE CACHE FILE: '${plist}.plist'"
else
	echo "FAILED TO WRITE CACHE FILE: '${plist}.plist'"
	exit 1
fi
exit 0
